﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HeadFirstDesignPatterns
{
    class WeatherData : ISubject {
        private float temperature;
        private float humidity;
        private float pressure;
        private List<IObserver> observers;

        public WeatherData() {
            this.observers = new List<IObserver>();
        }

        public void RegisterObserver(IObserver o) {
            observers.Add(o);
        }

        public void RemoveObserver(IObserver o) {
            observers.Remove(o);
        }

        public void Notify() {
            foreach (IObserver observer in observers) {
                observer.Update(temperature,humidity,pressure);
            }
        }

        public void MeasurementChanged() {
            Notify();
        }

        public void SetMessurement(float temp,float humidi, float press) {
            temperature = temp;
            humidity = humidi;
            pressure = press;
            MeasurementChanged();
        }
    }
}
